package com.hksj.Intelligentmanagement.mqtt.listener;

import com.hksj.Intelligentmanagement.mqtt.annotation.MqttSubscription;
import com.hksj.Intelligentmanagement.mqtt.config.MqttConfig;
import com.hksj.Intelligentmanagement.mqtt.constant.TopicConstant;
import com.hksj.Intelligentmanagement.service.CallTaskOrderService;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;

@MqttSubscription(topics = {TopicConstant.client_complete_order},targetClient = MqttConfig.SECOND_CLIENT)
public class CompleteOrderListener extends ListenerMqttClientSupport implements MqttListener{

    @Autowired
    private CallTaskOrderService taskOrderService;

    @Override
    public void receive(String topic, MqttMessage mqttMessage) {
        getMqttClient().getCallBackAdapter().getExecutor().execute(() -> {
            String operatingRoomNo = new String(mqttMessage.getPayload());
            taskOrderService.complete(operatingRoomNo);
        });
    }
}
